package c.e.a.a.e;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Build.VERSION;
import c.e.a.a.e.b.j;
import c.e.a.a.f.n.m;
import c.e.b.i.i.d;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Calendar;
import java.util.TimeZone;

public final class e implements m {
    public final c.e.b.i.a a;
    public final ConnectivityManager b;
    public final URL c;
    public final c.e.a.a.f.r.a d;
    public final c.e.a.a.f.r.a e;
    public final int f;

    public static final class a {
        public final URL a;
        public final j b;
        public final String c;

        public a(URL url, j jVar, String str) {
            this.a = url;
            this.b = jVar;
            this.c = str;
        }
    }

    public static final class b {
        public final int a;
        public final URL b;
        public final long c;

        public b(int i, URL url, long j) {
            this.a = i;
            this.b = url;
            this.c = j;
        }
    }

    public e(Context context, c.e.a.a.f.r.a aVar, c.e.a.a.f.r.a aVar2) {
        c.e.b.i.i.e eVar = new c.e.b.i.i.e();
        ((c.e.a.a.e.b.b) c.e.a.a.e.b.b.a).a(eVar);
        this.a = new d(eVar);
        this.b = (ConnectivityManager) context.getSystemService("connectivity");
        this.c = c(a.c);
        this.d = aVar2;
        this.e = aVar;
        this.f = 40000;
    }

    public static URL c(String str) {
        try {
            return new URL(str);
        } catch (MalformedURLException e) {
            throw new IllegalArgumentException(c.b.a.a.a.D("Invalid url: ", str), e);
        }
    }

    public c.e.a.a.f.e a(c.e.a.a.f.e eVar) {
        int i;
        NetworkInfo activeNetworkInfo = this.b.getActiveNetworkInfo();
        c.e.a.a.f.e.a i2 = eVar.i();
        String str = "sdk-version";
        i2.c().put(str, String.valueOf(VERSION.SDK_INT));
        i2.c().put("model", Build.MODEL);
        i2.c().put("hardware", Build.HARDWARE);
        i2.c().put("device", Build.DEVICE);
        i2.c().put("product", Build.PRODUCT);
        i2.c().put("os-uild", Build.ID);
        i2.c().put("manufacturer", Build.MANUFACTURER);
        i2.c().put("fingerprint", Build.FINGERPRINT);
        Calendar.getInstance();
        String str2 = "tz-offset";
        i2.c().put(str2, String.valueOf((long) (TimeZone.getDefault().getOffset(Calendar.getInstance().getTimeInMillis()) / 1000)));
        if (activeNetworkInfo == null) {
            c.e.a.a.e.b.o.b bVar = c.e.a.a.e.b.o.b.NONE;
            i = -1;
        } else {
            i = activeNetworkInfo.getType();
        }
        i2.c().put("net-type", String.valueOf(i));
        i = 0;
        c.e.a.a.e.b.o.a aVar;
        if (activeNetworkInfo == null) {
            aVar = c.e.a.a.e.b.o.a.UNKNOWN_MOBILE_SUBTYPE;
        } else {
            int subtype = activeNetworkInfo.getSubtype();
            if (subtype == -1) {
                aVar = c.e.a.a.e.b.o.a.COMBINED;
                i = 100;
            } else if (((c.e.a.a.e.b.o.a) c.e.a.a.e.b.o.a.w.get(subtype)) != null) {
                i = subtype;
            }
        }
        i2.c().put("mobile-subtype", String.valueOf(i));
        return i2.b();
    }

    /* JADX WARNING: Missing block: B:49:0x0213, code skipped:
            r19 = r0;
            r20 = r12;
     */
    /* JADX WARNING: Missing block: B:50:0x0217, code skipped:
            if (r9 != null) goto L_0x021c;
     */
    /* JADX WARNING: Missing block: B:51:0x0219, code skipped:
            r12 = " requestTimeMs";
     */
    /* JADX WARNING: Missing block: B:52:0x021c, code skipped:
            r12 = r20;
     */
    /* JADX WARNING: Missing block: B:53:0x021e, code skipped:
            if (r10 != null) goto L_0x0226;
     */
    /* JADX WARNING: Missing block: B:54:0x0220, code skipped:
            r12 = c.b.a.a.a.D(r12, " requestUptimeMs");
     */
    /* JADX WARNING: Missing block: B:56:0x022a, code skipped:
            if (r12.isEmpty() == false) goto L_0x0244;
     */
    /* JADX WARNING: Missing block: B:59:0x024d, code skipped:
            throw new java.lang.IllegalStateException(c.b.a.a.a.D(r11, r12));
     */
    public c.e.a.a.f.n.g b(c.e.a.a.f.n.f r32) {
        /*
        r31 = this;
        r1 = r31;
        r2 = c.e.a.a.f.n.g.a.TRANSIENT_ERROR;
        r0 = new java.util.HashMap;
        r0.<init>();
        r3 = r32;
        r3 = (c.e.a.a.f.n.a) r3;
        r4 = r3.a;
        r4 = r4.iterator();
    L_0x0013:
        r5 = r4.hasNext();
        if (r5 == 0) goto L_0x003f;
    L_0x0019:
        r5 = r4.next();
        r5 = (c.e.a.a.f.e) r5;
        r6 = r5.g();
        r7 = r0.containsKey(r6);
        if (r7 != 0) goto L_0x0035;
    L_0x0029:
        r7 = new java.util.ArrayList;
        r7.<init>();
        r7.add(r5);
        r0.put(r6, r7);
        goto L_0x0013;
    L_0x0035:
        r6 = r0.get(r6);
        r6 = (java.util.List) r6;
        r6.add(r5);
        goto L_0x0013;
    L_0x003f:
        r4 = new java.util.ArrayList;
        r4.<init>();
        r0 = r0.entrySet();
        r0 = r0.iterator();
    L_0x004c:
        r5 = r0.hasNext();
        r6 = "CctTransportBackend";
        r7 = 0;
        if (r5 == 0) goto L_0x024e;
    L_0x0055:
        r5 = r0.next();
        r5 = (java.util.Map.Entry) r5;
        r8 = r5.getValue();
        r8 = (java.util.List) r8;
        r9 = 0;
        r8 = r8.get(r9);
        r8 = (c.e.a.a.f.e) r8;
        r18 = c.e.a.a.e.b.p.DEFAULT;
        r9 = r1.e;
        r9 = r9.a();
        r9 = java.lang.Long.valueOf(r9);
        r10 = r1.d;
        r10 = r10.a();
        r10 = java.lang.Long.valueOf(r10);
        r11 = c.e.a.a.e.b.k.a.ANDROID_FIREBASE;
        r12 = "sdk-version";
        r12 = r8.f(r12);
        r20 = java.lang.Integer.valueOf(r12);
        r12 = "model";
        r21 = r8.a(r12);
        r12 = "hardware";
        r22 = r8.a(r12);
        r12 = "device";
        r23 = r8.a(r12);
        r12 = "product";
        r24 = r8.a(r12);
        r12 = "os-uild";
        r25 = r8.a(r12);
        r12 = "manufacturer";
        r26 = r8.a(r12);
        r12 = "fingerprint";
        r27 = r8.a(r12);
        r8 = new c.e.a.a.e.b.c;
        r19 = r8;
        r19.m5405init(r20, r21, r22, r23, r24, r25, r26, r27);
        r14 = new c.e.a.a.e.b.e;
        r14.m5407init(r11, r8);
        r8 = r5.getKey();	 Catch:{ NumberFormatException -> 0x00d2 }
        r8 = (java.lang.String) r8;	 Catch:{ NumberFormatException -> 0x00d2 }
        r8 = java.lang.Integer.parseInt(r8);	 Catch:{ NumberFormatException -> 0x00d2 }
        r8 = java.lang.Integer.valueOf(r8);	 Catch:{ NumberFormatException -> 0x00d2 }
        r16 = r7;
        r15 = r8;
        goto L_0x00db;
    L_0x00d2:
        r8 = r5.getKey();
        r8 = (java.lang.String) r8;
        r15 = r7;
        r16 = r8;
    L_0x00db:
        r7 = new java.util.ArrayList;
        r7.<init>();
        r5 = r5.getValue();
        r5 = (java.util.List) r5;
        r5 = r5.iterator();
    L_0x00ea:
        r8 = r5.hasNext();
        r11 = "Missing required properties:";
        r12 = "";
        if (r8 == 0) goto L_0x0213;
    L_0x00f4:
        r8 = r5.next();
        r8 = (c.e.a.a.f.e) r8;
        r13 = r8.d();
        r19 = r0;
        r0 = r13.a;
        r17 = r5;
        r5 = new c.e.a.a.a;
        r20 = r12;
        r12 = "proto";
        r5.m1152init(r12);
        r5 = r0.equals(r5);
        if (r5 == 0) goto L_0x011d;
    L_0x0113:
        r0 = r13.b;
        r5 = new c.e.a.a.e.b.f$a;
        r5.m5408init();
        r5.d = r0;
        goto L_0x013e;
    L_0x011d:
        r5 = new c.e.a.a.a;
        r12 = "json";
        r5.m1152init(r12);
        r5 = r0.equals(r5);
        if (r5 == 0) goto L_0x01fa;
    L_0x012a:
        r0 = new java.lang.String;
        r5 = r13.b;
        r12 = "UTF-8";
        r12 = java.nio.charset.Charset.forName(r12);
        r0.<init>(r5, r12);
        r5 = new c.e.a.a.e.b.f$a;
        r5.m5408init();
        r5.e = r0;
    L_0x013e:
        r12 = r8.e();
        r0 = java.lang.Long.valueOf(r12);
        r5.a = r0;
        r12 = r8.h();
        r0 = java.lang.Long.valueOf(r12);
        r5.c = r0;
        r0 = r8.b();
        r12 = "tz-offset";
        r0 = r0.get(r12);
        r0 = (java.lang.String) r0;
        if (r0 != 0) goto L_0x0163;
    L_0x0160:
        r12 = 0;
        goto L_0x016b;
    L_0x0163:
        r0 = java.lang.Long.valueOf(r0);
        r12 = r0.longValue();
    L_0x016b:
        r0 = java.lang.Long.valueOf(r12);
        r5.f = r0;
        r0 = "net-type";
        r0 = r8.f(r0);
        r12 = c.e.a.a.e.b.o.b.u;
        r0 = r12.get(r0);
        r0 = (c.e.a.a.e.b.o.b) r0;
        r12 = "mobile-subtype";
        r12 = r8.f(r12);
        r13 = c.e.a.a.e.b.o.a.w;
        r12 = r13.get(r12);
        r12 = (c.e.a.a.e.b.o.a) r12;
        r13 = new c.e.a.a.e.b.i;
        r13.m5412init(r0, r12);
        r5.g = r13;
        r0 = r8.c();
        if (r0 == 0) goto L_0x01a0;
    L_0x019a:
        r0 = r8.c();
        r5.b = r0;
    L_0x01a0:
        r0 = r5.a;
        if (r0 != 0) goto L_0x01a7;
    L_0x01a4:
        r12 = " eventTimeMs";
        goto L_0x01a9;
    L_0x01a7:
        r12 = r20;
    L_0x01a9:
        r0 = r5.c;
        if (r0 != 0) goto L_0x01b3;
    L_0x01ad:
        r0 = " eventUptimeMs";
        r12 = c.b.a.a.a.D(r12, r0);
    L_0x01b3:
        r0 = r5.f;
        if (r0 != 0) goto L_0x01bd;
    L_0x01b7:
        r0 = " timezoneOffsetSeconds";
        r12 = c.b.a.a.a.D(r12, r0);
    L_0x01bd:
        r0 = r12.isEmpty();
        if (r0 == 0) goto L_0x01f0;
    L_0x01c3:
        r0 = new c.e.a.a.e.b.f;
        r8 = r5.a;
        r21 = r8.longValue();
        r8 = r5.b;
        r11 = r5.c;
        r24 = r11.longValue();
        r11 = r5.d;
        r12 = r5.e;
        r13 = r5.f;
        r28 = r13.longValue();
        r5 = r5.g;
        r20 = r0;
        r23 = r8;
        r26 = r11;
        r27 = r12;
        r30 = r5;
        r20.m5409init(r21, r23, r24, r26, r27, r28, r30);
        r7.add(r0);
        goto L_0x020d;
    L_0x01f0:
        r0 = new java.lang.IllegalStateException;
        r2 = c.b.a.a.a.D(r11, r12);
        r0.<init>(r2);
        throw r0;
    L_0x01fa:
        r5 = b.i.b.f.y0(r6);
        r8 = 1;
        r8 = new java.lang.Object[r8];
        r11 = 0;
        r8[r11] = r0;
        r0 = "Received event of unsupported encoding %s. Skipping...";
        r0 = java.lang.String.format(r0, r8);
        android.util.Log.w(r5, r0);
    L_0x020d:
        r5 = r17;
        r0 = r19;
        goto L_0x00ea;
    L_0x0213:
        r19 = r0;
        r20 = r12;
        if (r9 != 0) goto L_0x021c;
    L_0x0219:
        r12 = " requestTimeMs";
        goto L_0x021e;
    L_0x021c:
        r12 = r20;
    L_0x021e:
        if (r10 != 0) goto L_0x0226;
    L_0x0220:
        r0 = " requestUptimeMs";
        r12 = c.b.a.a.a.D(r12, r0);
    L_0x0226:
        r0 = r12.isEmpty();
        if (r0 == 0) goto L_0x0244;
    L_0x022c:
        r0 = new c.e.a.a.e.b.g;
        r5 = r9.longValue();
        r12 = r10.longValue();
        r9 = r0;
        r10 = r5;
        r17 = r7;
        r9.m5410init(r10, r12, r14, r15, r16, r17, r18);
        r4.add(r0);
        r0 = r19;
        goto L_0x004c;
    L_0x0244:
        r0 = new java.lang.IllegalStateException;
        r2 = c.b.a.a.a.D(r11, r12);
        r0.<init>(r2);
        throw r0;
    L_0x024e:
        r0 = new c.e.a.a.e.b.d;
        r0.m5406init(r4);
        r4 = r1.c;
        r3 = r3.b;
        if (r3 == 0) goto L_0x0276;
    L_0x0259:
        r3 = r32;
        r3 = (c.e.a.a.f.n.a) r3;	 Catch:{ IllegalArgumentException -> 0x0271 }
        r3 = r3.b;	 Catch:{ IllegalArgumentException -> 0x0271 }
        r3 = c.e.a.a.e.a.a(r3);	 Catch:{ IllegalArgumentException -> 0x0271 }
        r5 = r3.b;	 Catch:{ IllegalArgumentException -> 0x0271 }
        if (r5 == 0) goto L_0x0268;
    L_0x0267:
        r7 = r5;
    L_0x0268:
        r3 = r3.a;	 Catch:{ IllegalArgumentException -> 0x0271 }
        if (r3 == 0) goto L_0x0276;
    L_0x026c:
        r4 = c(r3);	 Catch:{ IllegalArgumentException -> 0x0271 }
        goto L_0x0276;
    L_0x0271:
        r0 = c.e.a.a.f.n.g.a();
        return r0;
    L_0x0276:
        r3 = 5;
        r8 = -1;
        r5 = new c.e.a.a.e.e$a;	 Catch:{ IOException -> 0x02af }
        r5.m1174init(r4, r0, r7);	 Catch:{ IOException -> 0x02af }
        r0 = new c.e.a.a.e.c;	 Catch:{ IOException -> 0x02af }
        r0.m1173init(r1);	 Catch:{ IOException -> 0x02af }
        r4 = c.e.a.a.e.d.a;	 Catch:{ IOException -> 0x02af }
        r0 = b.i.b.f.U0(r3, r5, r0, r4);	 Catch:{ IOException -> 0x02af }
        r0 = (c.e.a.a.e.e.b) r0;	 Catch:{ IOException -> 0x02af }
        r3 = r0.a;	 Catch:{ IOException -> 0x02af }
        r4 = 200; // 0xc8 float:2.8E-43 double:9.9E-322;
        if (r3 != r4) goto L_0x029b;
    L_0x0291:
        r3 = r0.c;	 Catch:{ IOException -> 0x02af }
        r0 = new c.e.a.a.f.n.b;	 Catch:{ IOException -> 0x02af }
        r5 = c.e.a.a.f.n.g.a.OK;	 Catch:{ IOException -> 0x02af }
        r0.m5427init(r5, r3);	 Catch:{ IOException -> 0x02af }
        return r0;
    L_0x029b:
        r0 = 500; // 0x1f4 float:7.0E-43 double:2.47E-321;
        if (r3 >= r0) goto L_0x02a9;
    L_0x029f:
        r0 = 404; // 0x194 float:5.66E-43 double:1.996E-321;
        if (r3 != r0) goto L_0x02a4;
    L_0x02a3:
        goto L_0x02a9;
    L_0x02a4:
        r0 = c.e.a.a.f.n.g.a();	 Catch:{ IOException -> 0x02af }
        return r0;
    L_0x02a9:
        r0 = new c.e.a.a.f.n.b;	 Catch:{ IOException -> 0x02af }
        r0.m5427init(r2, r8);	 Catch:{ IOException -> 0x02af }
        return r0;
    L_0x02af:
        r0 = move-exception;
        r3 = "Could not make request to the backend";
        b.i.b.f.p0(r6, r3, r0);
        r0 = new c.e.a.a.f.n.b;
        r0.m5427init(r2, r8);
        return r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.e.a.a.e.e.b(c.e.a.a.f.n.f):c.e.a.a.f.n.g");
    }
}
